package com.shelpe.services.sinbad.repository.jpa;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.shelpe.services.sinbad.entity.jpa.Product;

public interface ProductRepository extends CrudRepository<Product, Long>, JpaSpecificationExecutor<Product> {
	List<Product> findTop10ByUserIDOrderBySalesDesc(long userID);
	
	int countByUserID(long userID);

	Page<Product> findAll(Specification<Product> spec, Pageable pageable);

	Page<Product> findByUserID(long userID, Pageable pageable);
	
	@Query("select p.userID from products p where p.userID!=?1 group by p.userID having count(1)<50")
	List<Long> findByUserIDNot(long userID);
}
